package csc420groupproject;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author drenz
 */
public class SymbolActionListener implements ActionListener {
    private GUI gui;

    public SymbolActionListener(GUI gui) {
        this.gui = gui;       
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        String command = evt.getActionCommand();

        if(this.gui.symbolMap.containsKey(command)) {
            int caretPos = this.gui.formulaField.getCaretPosition();
            StringBuffer oldText = new StringBuffer();

            oldText.append(this.gui.formulaField.getText());
            oldText.insert(caretPos, (String)this.gui.symbolMap.get(command));

            this.gui.formulaField.setText(oldText.toString());
            this.gui.formulaField.requestFocus();
        }
    }
}
